package oa.hleast.xswl.service.store.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.xswl.mapper.store.StoreReviewLogMapper;
import oa.hleast.xswl.pojo.domain.SysUser;
import oa.hleast.xswl.pojo.domain.store.StoreReviewLog;
import oa.hleast.xswl.service.ISysUserService;
import oa.hleast.xswl.service.store.StoreReviewLogService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: 302
 * @date: 2021-10-16 14:56:47
 * @description: 商家审核记录表(StoreReviewLog)接口实现
 */
@Slf4j
@AllArgsConstructor
@Transactional
@Service("storeReviewLogService")
public class StoreReviewLogServiceImpl extends ServiceImpl<StoreReviewLogMapper, StoreReviewLog> implements StoreReviewLogService {

    private final ISysUserService sysUserService;

    @Override
    public boolean saveLog(Long userId, Integer reviewStatus, Long storeId, String reviewRemark) {
        StoreReviewLog storeReviewLog = StoreReviewLog.builder()
                .reviewStatus(reviewStatus)
                .storeId(storeId)
                .reviewRemark("")
                .build();

        SysUser sysUser = sysUserService.getById(userId);
        if (ObjectUtils.isNotEmpty(sysUser)) {
            storeReviewLog.setOperationUserId(userId);
            storeReviewLog.setOperationUserName(sysUser.getUsername());
        } else {
            log.info("没有获取到操作用户 userID = {}", userId);
            storeReviewLog.setOperationUserId(0L);
        }
        boolean save = this.save(storeReviewLog);
        log.info("save = {}", save);
        return save;
    }
}
